package com.lanyou.cook.upload.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;

import com.lanyou.cook.upload.entity.TCookBuParamSet;

/**
 * 对T_Cook_Bu_Param_Set表的操作dao
 * @author ly-lihailang
 *
 */
public class TCookBuParamSetDao extends BaseDao<TCookBuParamSet>{
	/**
	 * 关系表到对象的映射
	 */
	RowMapper<TCookBuParamSet> mapper = new RowMapper<TCookBuParamSet>() {
		public TCookBuParamSet mapRow(ResultSet rs, int rowNum) throws SQLException {
			TCookBuParamSet rcd = new TCookBuParamSet();
			rcd.setCooBuParamSetId(rs.getString("COOK_BU_PARAM_SET_ID"));
			rcd.setParamName(rs.getString("PARAM_NAME"));
			rcd.setParamValue(rs.getString("PARAM_VALUE"));
			rcd.setRemark(rs.getString("REMARK"));
			rcd.setIsEnable(rs.getString("IS_ENABLE"));
			rcd.setCreator(rs.getString("CREATOR"));
			rcd.setCreated_date(rs.getDate("CREATED_DATE"));
			rcd.setModifier(rs.getString("MODIFIER"));
			rcd.setLastUpdatedDate(rs.getDate("LAST_UPDATED_DATE"));
			return rcd;
		}
	};
	
	@Override
	public TCookBuParamSet findByCode(String paramName) {
		System.out.println("into findByCode paramName:---"+paramName);
		String sql = "SELECT * FROM t_cook_bu_param_set WHERE PARAM_NAME = ?";
		TCookBuParamSet tCookBuParamSet = new TCookBuParamSet();
		try{
			tCookBuParamSet = this.getJdbcTemplate().queryForObject(sql, mapper,paramName);
			return tCookBuParamSet;
		}catch(DataAccessException e){
			e.printStackTrace();
			System.out.println("DataAccessException code:--"+paramName);
			return null;
		}
	};

}
